//
//  FeedbackOnLine.m
//  BSS
//
//  Created by Juvi on 13-5-31.
//  Copyright (c) 2013年 juvid. All rights reserved.
//

#import "FeedbackOnLine.h"
#import "DetectionSystemVersion.h"
#import "SBJson.h"
#import "UIColor+expanded.h"
@interface FeedbackOnLine (){
    int vieY;
}

@end

@implementation FeedbackOnLine

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
   
    [self BackButton];
    [ self.txtFeedBack.layer setBorderWidth:1.5];
    [self.txtFeedBack.layer setBorderColor:[UIColor colorWithHexString:@"0xd3d3d3"].CGColor];
    [self.txtFeedBack.layer setShadowColor:[UIColor colorWithHexString:@"0xd3d3d3"].CGColor];
    
     self.view.backgroundColor=[UIColor colorWithHexString:@"0xe4e4e4"];
    // Do any additional setup after loading the view from its nib.
}

-(void)BackButton{
    if ([[DetectionSystemVersion alloc]Version]) {
        self.edgesForExtendedLayout=UIRectEdgeNone;
    }
    self.navigationItem.titleView=[DetectionSystemVersion SetBarTitle:@"百事搜"];
    [self.navigationItem setHidesBackButton:YES];
    UIButton *btnBack=[[DetectionSystemVersion alloc]BackButton];
    [btnBack addTarget:self action:@selector(BackReturn:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:btnBack];
    self.navigationItem.leftBarButtonItem=backItem;
    
}
-(void)viewDidAppear:(BOOL)animated{
    vieY=self.view.frame.origin.y;
     NSLog(@"%f",self.view.frame.origin.y);
}
#pragma mark 导航栏按钮事件
-(void)BackReturn:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
    [tRequest clearDelegatesAndCancel];
    [tRequest cancel];
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    [NSThread cancelPreviousPerformRequestsWithTarget:self];
}
#pragma mark 异步数据请求
-(void)GetDatas{
           tRequest=[[[ScreenAccess alloc]init]ASIOpinion:self.txtFeedBack.text];
       [tRequest setDelegate:self];
    [tRequest setUsername:@"allMessage"];
    
}
-(void)requestFinished:(ASIHTTPRequest*)request{
    
    NSString *response = [request responseString];
    SBJsonParser * parser = [[SBJsonParser alloc] init];
    NSMutableDictionary *Result = [parser objectWithString:response];
    if ([request.username isEqual:@"allMessage"]){
        BOOL IsSuccess=[[[Result objectForKey:@"Response"]objectForKey:@"status"]integerValue]==200?YES:NO;
        if (IsSuccess==YES) {
               }
    }
   
    
}

-(void)requestFailed:(ASIHTTPRequest*)request{
}
#pragma mark TscrollView viewHeight
-(void)ViewAnimatios:(int)viewHeight{
   
    [UIView beginAnimations:@"ResizeForKeyboard" context:(__bridge void *)((UIView *)self.view)];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:nil];
    self.view.frame = CGRectMake(0.0f, vieY-viewHeight, self.view.frame.size.width,self.view.frame.size.height);
   
    //    vieNewfav.frame=CGRectMake(0, self.view.frame.size.height-60, 320, 140);
    [UIView commitAnimations];
}
- (void)textViewDidChange:(UITextView *)textView{
    if (textView.text.length==0) {
        self.labMark.hidden=NO;
    }
    else{
        self.labMark.hidden=YES;
    }
    float vieHight=self.txtFeedBack.contentSize.height;
    if (vieHight>60) {
        [self ViewAnimatios:vieHight];
    }
}

- (IBAction)btnSubmit:(id)sender{
    [self GetDatas];
    
}

- (IBAction)btnCancle:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)HideKey:(id)sender {
    [self.txtFeedBack resignFirstResponder];
    [self.txtUserName resignFirstResponder];
    [self ViewAnimatios:0];
}
@end
